<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>addressof</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="revision_history.html" title="Revision History">
<link rel="next" href="allocator_access.html" title="allocator_access">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="revision_history.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="allocator_access.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.addressof"></a><a class="link" href="addressof.html" title="addressof">addressof</a>
</h2></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="addressof.html#core.addressof.header_boost_core_addressof_hpp">Header
      &lt;boost/core/addressof.hpp&gt;</a></span></dt></dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm393"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          Brad King
        </li>
<li class="listitem">
          Douglas Gregor
        </li>
<li class="listitem">
          Peter Dimov
        </li>
<li class="listitem">
          Glen Fernandes
        </li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.addressof.header_boost_core_addressof_hpp"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp" title="Header &lt;boost/core/addressof.hpp&gt;">Header
      &lt;boost/core/addressof.hpp&gt;</a>
</h3></div></div></div>
<p>
        The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">addressof</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        defines the function template <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code>.
        <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> returns
        the address of <code class="computeroutput"><span class="identifier">x</span></code>. Ordinarily,
        this address can be obtained by <code class="computeroutput"><span class="special">&amp;</span><span class="identifier">x</span></code>, but the unary <code class="computeroutput"><span class="special">&amp;</span></code>
        operator can be overloaded. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code>
        avoids calling used-defined <code class="computeroutput"><span class="keyword">operator</span><span class="special">&amp;()</span></code>.
      </p>
<p>
        <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code> was originally contributed by
        Brad King based on ideas from discussion with Doug Gregor.
      </p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.addressof.header_boost_core_addressof_hpp.synopsis"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp.synopsis" title="Synopsis">Synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">addressof</span><span class="special">(</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">x</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.addressof.header_boost_core_addressof_hpp.example"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp.example" title="Example">Example</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">addressof</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">struct</span> <span class="identifier">useless_type</span> <span class="special">{</span> <span class="special">};</span>

<span class="keyword">class</span> <span class="identifier">nonaddressable</span> <span class="special">{</span>
    <span class="identifier">useless_type</span> <span class="keyword">operator</span><span class="special">&amp;()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>

<span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span>
    <span class="identifier">nonaddressable</span> <span class="identifier">x</span><span class="special">;</span>
    <span class="identifier">nonaddressable</span><span class="special">*</span> <span class="identifier">xp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
    <span class="comment">// nonaddressable* xpe = &amp;x; /* error */</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.addressof.header_boost_core_addressof_hpp.notes"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp.notes" title="Notes">Notes</a>
</h4></div></div></div>
<p>
          In C++11 and above, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code>
          is conditionally <code class="computeroutput"><span class="keyword">constexpr</span></code>
          when possible. This is indicated by <code class="computeroutput"><span class="identifier">BOOST_CORE_NO_CONSTEXPR_ADDRESSOF</span></code>
          not being defined.
        </p>
<p>
          With supported compilers, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code>
          is always <code class="computeroutput"><span class="keyword">constexpr</span></code> by leveraging
          compiler intrinsics. This is indicated by <code class="computeroutput"><span class="identifier">BOOST_CORE_HAS_BUILTIN_ADDRESSOF</span></code>
          being defined.
        </p>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="revision_history.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="allocator_access.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
